package Design_patterns.creator_mode.prototype.demo4;

import java.io.*;

/**
 * @description: 原型模式深拷贝
 **/

public class CitationTest {
    public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException {
        //创建原型对象
        Citation citation = new Citation();

        Student student = new Student();
        student.setName("张三");

        citation.setStudent(student);

        //创建对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\Users\\10322\\Desktop\\a.txt"));
        //写对象
        oos.writeObject(citation);
        //释放资源
        oos.close();

        //读取对象
        //创建对象输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\Users\\10322\\Desktop\\a.txt"));
        //读取对象
        Citation clone = (Citation) ois.readObject();
        //释放资源
        ois.close();

        //克隆对象
        clone.getStudent().setName("李四");


        citation.show();
        clone.show();
        /*
        同学：张三在2020学年第一学期中表现优秀，被评为三好学生，特发此状
        同学：李四在2020学年第一学期中表现优秀，被评为三好学生，特发此状
         */
    }
}
